package org.oep.jmingle;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import org.oep.widgets.TextWidget;

public class StatusBar {
	private static final int WATERMARK_COLOR = 0x72CC70;
	private static final int BG_COLOR = 0xcdffbf;
	private static final int PADDING = 3;
	private static int HEIGHT = JMingle.BOLD_FONT.getHeight();
	
	
	public static void paint(Graphics g, String msg, String watermark, TextWidget marquee, Image fav) { 
		int maxHeight = JMingle.DEFAULT_FONT.getHeight();
		int offset = 0;
		
		if(marquee != null) {
			offset = g.getFont().charsWidth(msg.toCharArray(), 0, msg.length());
			marquee.setPosition(PADDING + offset, marquee.getY() - 1);
			marquee.setLife(marquee.getLife() - 1);
			maxHeight = Math.max(maxHeight, marquee.getFont().getHeight());
		}
		
		if(fav != null) maxHeight = Math.max(maxHeight, fav.getHeight());
		
		// Draw base bar
		g.setColor(BG_COLOR); g.fillRect(0, 0, g.getClipWidth(), maxHeight + 2 * PADDING);
		g.setColor(0); g.drawLine(0, maxHeight + 2 * PADDING, g.getClipWidth(), maxHeight + 2 * PADDING);
		
		// Watermark!
		if(watermark != null) {
			g.setColor(WATERMARK_COLOR);
			g.setFont(JMingle.BOLD_FONT);
			g.drawString(watermark, g.getClipWidth() / 2, (maxHeight + 2 * PADDING) / 2 - JMingle.BOLD_FONT.getHeight() / 2, Graphics.TOP | Graphics.HCENTER);
		}
		
		g.setColor(0);
		g.setFont(JMingle.DEFAULT_FONT);
		g.drawString(msg, PADDING, (maxHeight + 2 * PADDING) / 2 - JMingle.DEFAULT_FONT.getHeight() / 2, Graphics.TOP | Graphics.LEFT);
		
		if(marquee != null)
			marquee.paint(g, PADDING + offset, (maxHeight + 2 * PADDING) / 2 - marquee.getFont().getHeight() / 2, Graphics.TOP | Graphics.LEFT);
		
		if(fav != null)
			g.drawImage(fav, g.getClipWidth() - PADDING, PADDING, Graphics.RIGHT | Graphics.TOP);
		
		HEIGHT = maxHeight + 2 * PADDING;
	}
	
	public static int getHeight() {
		return HEIGHT;
	}

}
